package com.txunda.zhuohired.aty.user.resume;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.ants.theantsgo.util.JSONUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;
import com.txunda.zhuohired.R;
import com.txunda.zhuohired.base.BaseAty;
import com.txunda.zhuohired.dialog.JoinJobDialog;
import com.txunda.zhuohired.dialog.JoinJobEndDialog;
import com.txunda.zhuohired.http.pst.ResumePst;

import java.util.Map;

/**
 * 创建人： Txd_Cjh
 * 创建时间： 2018/3/7 11:34
 * 功能描述：添加项目经验
 * 联系方式：jiahuanchen@126.com
 */

public class AddProjectAty extends BaseAty {
    /**
     * 标题
     */
    @ViewInject(R.id.tv_layout_white_center)
    private TextView tv_layout_white_center;
    /**
     * 保存
     */
    @ViewInject(R.id.tv_layout_white_right)
    private TextView tv_layout_white_right;
    /**
     * 开始时间
     */
    @ViewInject(R.id.tv_add_project_start)
    private TextView tv_add_project_start;
    /**
     * 结束时间
     */
    @ViewInject(R.id.tv_add_project_end)
    private TextView tv_add_project_end;
    /**
     * 项目名称
     */
    @ViewInject(R.id.et_add_project_name)
    private EditText et_add_project_name;
    /**
     * 项目描述
     */
    @ViewInject(R.id.et_add_project_describe)
    private EditText et_add_project_describe;

    private String project_name = "";//项目名称
    private String start_time = "";//开始时间
    private String end_time = "";//结束时间
    private String project_describe = "";//项目描述
    private ResumePst resumePst;
    private String token = "";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        showStatusBar(R.id.layout_white_head);
        tv_layout_white_center.setText("项目经验");
        tv_layout_white_right.setVisibility(View.VISIBLE);
        tv_layout_white_right.setText("保存");
    }

    @Override
    @OnClick({R.id.ll_add_project_start, R.id.ll_add_project_end, R.id.tv_layout_white_right})
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.ll_add_project_start://开始时间
                JoinJobDialog joinJobDialog = new JoinJobDialog(this, "1", new JoinJobDialog.JoinJobListener() {
                    @Override
                    public void onJoinJob(String birthday) {
                        tv_add_project_start.setText(birthday);
                    }
                });
                joinJobDialog.show();
                break;
            case R.id.ll_add_project_end://结束时间
                JoinJobEndDialog joinJobEndDialog = new JoinJobEndDialog(this, new JoinJobEndDialog
                        .JoinJobEndListener() {
                    @Override
                    public void onJoinJobEnd(String birthday) {
                        tv_add_project_end.setText(birthday);
                    }
                });
                joinJobEndDialog.show();
                break;
            case R.id.tv_layout_white_right:
                project_name = et_add_project_name.getText().toString().trim();
                start_time = tv_add_project_start.getText().toString().trim();
                end_time = tv_add_project_end.getText().toString().trim();
                project_describe = et_add_project_describe.getText().toString().trim();
                if (TextUtils.isEmpty(project_name)) {
                    showErrorTip("请输入项目名称");
                    return;
                }
                if (TextUtils.isEmpty(start_time)) {
                    showErrorTip("请选择开始时间");
                    return;
                }
                if (TextUtils.isEmpty(end_time)) {
                    showErrorTip("请选择结束时间");
                    return;
                }
                if ("至今".equals(end_time)) {
                    end_time = "0";
                }
                if (TextUtils.isEmpty(project_describe)) {
                    showErrorTip("请输入项目描述");
                    return;
                }
                resumePst.addJob(token, project_name, project_describe, start_time, end_time);
                break;
        }
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.aty_add_project;
    }

    @Override
    protected void initialized() {
        resumePst = new ResumePst(this);
        token = application.getUserInfo().get("data");
    }

    @Override
    protected void requestData() {

    }

    @Override
    public void onComplete(String requestUrl, String jsonStr) {
        super.onComplete(requestUrl, jsonStr);
        if(requestUrl.contains("addJob")){
            Map<String, String> map = JSONUtils.parseKeyAndValueToMap(jsonStr);
            showRightTip(map.get("message"));
            finish();
            return;
        }
    }
}
